#include <iostream>

using namespace std;

typedef long long LL;

int n, m, k, x;


LL qpow(LL a, LL b, LL p)
{
	LL ret = 1;
	while(b)
	{
		if(b & 1) ret = ret * a % p;
		b >>= 1;
		a = a * a % p;
	}
	return ret;
}


int main()
{
	cin >> n >> m >> k >> x;

	LL t = qpow(10, k, n) % 10;
	cout << x + (t * m) % 10 << endl;
	return 0;
}
